//
// Created by 紫霄 on 2020/4/30.
//

#ifndef LEETCODE_66_H
#define LEETCODE_66_H
#include <vector>
using namespace std;
class Solution {
public:
  vector<int> constructArr(vector<int> &a) {
    if (a.empty()) {
      return a;
    }
    vector<int> ans(a.size(), 1);
    vector<int> tempA(a.size(), 1);
    tempA[0] = 1;
    for (int i = 1; i < a.size(); ++i) {
      tempA[i] = tempA[i - 1] * a[i - 1];
    }
    ans[a.size() - 1] = 1;
    for (int i = a.size() - 2; - 1 < i; --i) {
      ans[i] = ans[i + 1] * a[i + 1];
    }
    for (int i = 0; i < a.size(); ++i) {
      ans[i] *= tempA[i];
    }
    return ans;
  }
};
#endif // LEETCODE_66_H
